using System;
using System.Linq;
using System.Collections.Generic;
using DevExpress.CodeRush.StructuralParser;

namespace CR.StyleCop.Naming {
    public class VariableNamesMustNotBePrefixedSearcher : BaseStyleCopIssueSearcher<IFieldElement> {
        // TODO (fen): Move this to the config dialog.
        private static string[] Prefixes = new[] { "m_", "s_" };

        public override IEnumerable<StyleCopIssue> FindIssues(IEnumerable<IFieldElement> elements) {
            return elements.Where(f => IsPrefixed(f))
                .Select(f => new StyleCopIssue {
                    Element = f,
                    IssueDescription = StyleCop.Resource.VariableNamesMustNotBePrefixedSearcherIssueDescription
                });
        }

        private static bool IsPrefixed(IFieldElement field) {
            return Prefixes.Where(prefix => field.Name.StartsWith(prefix)).Count() != 0;
        }
    }
}